
function[sigma_dyn, fitness_dyn, generations] = CMSA

global LensParms; % phsyical parameters
LensParms.h = 1; LensParms.b = 20; LensParms.R = 7; LensParms.eps = 1.5;
LensParms.x_init = 3;
global Weighting;
Weighting = .9;
n = 15;

% here starts cmsa-es
mu = 5; lambda = 20;
x = LensParms.x_init*ones(n,1);
sigma = 1; sigma_stop = 1e-5;
C = eye(n);
tau = 1/sqrt(2*n); tau_c = 1 + n*(n+1)/(2*mu);
g = 0;

generations(g+1) = [g];
fitness_dyn(g+1) = [f_ges(x)];
sigma_dyn(g+1) = [sigma];


% here starts generation loop
while (sigma > sigma_stop)
	
	for l=1:lambda
		sigmaTilde(l) = sigma * exp(tau*randn());
		sTilde(:, l) = (det(chol(C))^(-1/n)*chol(C)')*randn(n,1);
		xTilde(:, l) = x + sigmaTilde(l)*sTilde(:,l);
		fTilde(l) = f_ges(xTilde(:, l));	
	endfor
	[fsorted, r] = sort(fTilde, 'ascend');
	x = 1/mu * sum(xTilde(:, r(1:mu)), 2);
	sigma = 1/mu * sum(sigmaTilde(r(1:mu)));
	SumSS = zeros(n, n);
	for m=1:mu; SumSS = SumSS + sTilde(:, r(m))*sTilde(:,r(m))'; endfor;
	C = (1-1/tau_c)*C + (1/tau_c) * (1/mu)*SumSS;
	C = 0.5*(C+C');
	g = g + 1;
	generations(g) = g;
	fitness_dyn(g) = [mean(vertcat(fTilde(:)))];
	sigma_dyn(g) = [sigma];
endwhile
end